Ext.define('component.giveCustomer.selectWindow', {
	extend : 'Ext.window.Window',
	callbackFun : function(record) {
		Ext.Msg.alert('提示', '回调函数未配置！');
	},
	config : {
		projectId : '',
		customerPhone : '',
		giveUpStatus : '',
		resourcesCode : ''
	},
	initComponent : function() {
		var me = this;
		var projectId = this.projectId;
		var customerPhone = this.customerPhone;
		var giveUpStatus = this.giveUpStatus;
		var resourcesCode = this.resourcesCode;
		var gridStore = Ext.create('Ext.data.Store', {
			fields : [ "id", "customerSexName", "customerOriginName",
					"peDocumentTypeName", "projectName", "userName",
					"customerName", "customerSex", "customerPhone",
					"customerOrigin", "peDocumentType", "peDocumentNumber",
					"pePostcode", "peContactAddress", "userId", "projectId",
					'intentionLevel' ],
			pageSize : 10, //页容量5条数据
			//是否在服务端排序 （true的话，在客户端就不能排序）
			remoteSort : false,
			proxy : {
				type : 'ajax',
				url : contextPath + '/customer/giveUp/giveUpList',
				reader : { //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
					type : 'json', //返回数据类型为json格式
					root : 'rows', //数据
					totalProperty : 'total' //数据总条数
				},
				actionMethods : {
					read : 'POST'
				}
			},
			listeners : {
				"beforeload" : function(store, op, options) {
					var params = {
						"customerPhone" : customerPhone,
						"giveUpStatus" : giveUpStatus,
						"projectId" : projectId
					};
					Ext.apply(store.proxy.extraParams, params);
				}
			},
			autoLoad : true
		//即时加载数据
		});
		var columns = [ {
			text : "ID",
			dataIndex : 'id',
			hidden : true
		}, {
			text : "项目名称",
			dataIndex : 'projectName'
		}, {
			text : "经纪人",
			dataIndex : 'userName'
		}, {
			text : "客户名称",
			dataIndex : 'customerName'
		}, {
			text : "证件类型",
			dataIndex : 'peDocumentTypeName'
		}, {
			text : "证件号码",
			dataIndex : 'peDocumentNumber'
		}, {
			text : "性别",
			dataIndex : 'customerSexName'
		}, {
			text : "手机号码",
			dataIndex : 'customerPhone'
		} ];
	
		var grid = Ext.create('Ext.grid.Panel', {
			title : "客户列表",
			minHeight : 400,
			store : gridStore,
			columns : columns,
			bbar : [
				{
					text:'确认选择',
					icon:contextPath+'/resources/ExtJSicons/control/control_rewind_blue.png',
					handler:function(){
						var record = grid.getSelectionModel().getLastSelected();
						if(null==record){
	                		Ext.Msg.alert('提示', '请选择一个客户！');
	                		return;
	                	}
						var jsonRecord=Ext.JSON.encode(record.data);
	                	me.callbackFun(jsonRecord);
	                	me.close();
				 	}
				}
			      ],
			selModel : Ext.create('Ext.selection.CheckboxModel', {
				checkOnly : true,
				mode : 'single',
				allowDeselect : true
			})
		});

		var mainPanel = Ext.create('Ext.panel.Panel', {
			items : [  grid ]
		});

		var defaultConfig = {
			frame : true,
			title : '选择客户',
			width : 760,
			height : 500,
			layout : 'fit',
			items : [ mainPanel ],
		};
		Ext.apply(this, defaultConfig);
		this.callParent();
	}
});
